import pandas as pd
#安装pip --default-timeout=100 install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
import matplotlib.pyplot as plt
from pmdarima.arima import auto_arima
from pmdarima.arima import ADFTest
from sklearn.metrics import mean_squared_error, mean_absolute_error
import numpy as np
from util import draw_data
from statsmodels.tsa.arima_model import ARIMA
plt.rcParams['font.sans-serif'] = ['KaiTi']  # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
font = {'family': 'KaiTi',
        'weight': 'normal',
        'size': 14,
        }
# ARIMA模型的参数设置：p, d, q
p = 4
d = 1
q = 0
dataset=pd.read_csv('./data/2019allday.csv',index_col=0, header=0)
data = dataset['out_flow'].values

data_num = len(data)
train_num = int(data_num - 94)
train = data[:train_num]
test = data[train_num:]

history = [x for x in train]
predictions = list()
# 模型滚动预测（当前预测时刻的真实值会添加进下一个时刻的历史数据中，进行下一个时间片的预测）
for t in range(len(test)):
    model = ARIMA(history, order=(p, d, q))
    model_fit = model.fit(disp=0)
    output = model_fit.forecast()
    yhat = output[0]
    predictions.append(yhat)
    # 添加进新的真实数据，滚动预测
    obs = test[t]
    history.append(obs)
mse = mean_squared_error(test, predictions)
mae = mean_absolute_error(test, predictions)
print('Test MSE: %.3f' % mse)
print('Test MAE: %.3f' % mae)

np.save("./result/out/arima", predictions)









